package pe.edu.upc.dew.grupo02.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.support.WebApplicationContextUtils;

import pe.edu.upc.dew.grupo02.model.Pelicula;
import pe.edu.upc.dew.grupo02.service.IPeliculaService;

public class EstrenoServlet extends HttpServlet {
	
	private static final long serialVersionUID = 3073628194612743904L;
	
	private IPeliculaService peliculaService;
	
	@Override
	public void init(ServletConfig config) throws ServletException {

		this.peliculaService = WebApplicationContextUtils
				.getWebApplicationContext(config.getServletContext()).getBean(
						"PeliculaService", IPeliculaService.class);

	}

	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
		List<Pelicula> peliculas= peliculaService.getPeliculasPorEstado(2);
		
		request.setAttribute("peliculas", peliculas);
		request.getRequestDispatcher("Estrenos.jsp").forward(request,
				response);
	}
}